﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Text;
using System.ComponentModel;
using System.IO.IsolatedStorage;

namespace BuyTrainTicket
{
    public partial class SelectTicketType : PhoneApplicationPage
    {
        List<string> tickettypelist = new List<string>();

        public SelectTicketType()
        {
            InitializeComponent();
        }

        protected override void OnBackKeyPress(CancelEventArgs e)
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            settings["tickettypes"] = tickettypes.Text;
            settings.Save();
            base.OnBackKeyPress(e);
        }

        private void updatetypes(string type,bool ischecked)
        {
            if (!ischecked)
            {
                if (tickettypelist.Contains(type))
                {
                    tickettypelist.Remove(type);
                }
            }
            else
            {
                if (!tickettypelist.Contains(type))
                {
                    tickettypelist.Add(type);
                }
            }
            StringBuilder sb = new StringBuilder();
            foreach (string t in tickettypelist)
            {
                sb.Append(t + ";");
            }
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }
            tickettypes.Text = sb.ToString();
        }

        private void sw_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(sw.Content.ToString(),(bool)sw.IsChecked);
        }

        private void td_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(td.Content.ToString(), (bool)td.IsChecked);
        }

        private void yd_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(yd.Content.ToString(), (bool)yd.IsChecked);
        }

        private void ed_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(ed.Content.ToString(), (bool)ed.IsChecked);
        }

        private void gjrw_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(gjrw.Content.ToString(), (bool)gjrw.IsChecked);
        }

        private void rw_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(rw.Content.ToString(), (bool)rw.IsChecked);
        }

        private void yw_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(yw.Content.ToString(), (bool)yw.IsChecked);
        }

        private void rz_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(rz.Content.ToString(), (bool)rz.IsChecked);
        }

        private void yz_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(yz.Content.ToString(), (bool)yz.IsChecked);
        }

        private void wz_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            updatetypes(wz.Content.ToString(), (bool)wz.IsChecked);
        }
    }
}